package com.weixing.mall.provider.controller.admin;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.mapper.BuyerShowMapper;
import com.weixing.mall.provider.model.dto.BuyerShowChgStatusDto;
import com.weixing.mall.provider.model.dto.BuyerShowDto;
import com.weixing.mall.provider.model.query.BuyerShowQuery;
import com.weixing.mall.provider.service.IBuyerShowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wx
 * @Date 2019/8/7 14:44
 * @Version 1.0
 */
@RestController
@RequestMapping("buyershow")
@Api(value = "买家秀api",tags = "买家秀")
public class BuyerShowController extends BaseController {

    @Autowired
    private IBuyerShowService buyerShowService;
    @Autowired
    private BuyerShowMapper buyerShowMapper;


    @ApiOperation(value = "查询买家秀")
    @GetMapping("")
    public Result list(BuyerShowQuery buyerShowQuery){
        return ResultUtil.success(buyerShowService.findOfPage(initMpPage(),buyerShowQuery));
    }

    @ApiOperation(value = "新增")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@SysInfo SysAuth sysAuth, BuyerShowDto buyerShowDto){
        buyerShowService.save(buyerShowDto,sysAuth.getUid());
        return ResultUtil.success();
    }

    @ApiOperation(value = "批量删除场景")
    @PostMapping("delAll/{ids}")
    public Result delAll(@PathVariable int []ids){
        buyerShowService.delAll(ids);
        return ResultUtil.success();
    }

    @ApiOperation(value = "查询买家秀详情")
    @GetMapping("queryDetails/{id}")
    public Result queryDetails(@PathVariable Long id){
        return ResultUtil.success(buyerShowService.queryDetails(id));
    }

    @ApiOperation(value = "修改审核状态/是否展示/点赞数")
    @PostMapping("ChangeStatus")
    public Result ChangeStatus(@Validated BuyerShowChgStatusDto buyerShowChgStatusDto){
        //共用方法有BUG问题 这里只能直接mapper调用
        //buyerShowService.updateStatus(buyerShowChgStatusDto);
        buyerShowMapper.updateStatus(buyerShowChgStatusDto);
        return ResultUtil.success();
    }
}
